<template >
            <div class="todo-footer" v-show="totalCount">
                <label>
                <input type="checkbox" :checked="isAll"  @click="all" />
                <!-- 绑定计算属性，计算属性要写完整写法 -->
                <!-- <input type="checkbox" v-model="isAll"   /> -->
                </label>
                <span>
                <span>已完成{{completeCount}}</span> / 全部{{totalCount}}
                </span>
                <button class="btn btn-danger" @click="delAllComp()">清除已完成任务</button>
            </div>
</template>
<script>
export default {
    name:'MyFooter',
    props:['todos'],
    computed:{
        totalCount(){
            return this.todos.length
        },
        completeCount(){
            let n = 0;
            this.todos.forEach((todo) => {
                if(todo.done){
                    n++
                }
            });
            return n
        },
        isAll(){
            return this.completeCount === this.totalCount && this.totalCount>0
        }
        /* //计算属性的完整写法
        isAll:{
            set(val){
                this.allchecked(val)
            },
            get(){
                return this.completeCount === this.totalCount && this.totalCount>0
            }
        } */
    },
    methods: {
        delAllComp(){
            this.$emit('deleteAllCompleteTodo')
        },
        all(e){
            console.log(e.target.checked)
            this.$emit('allchecked',e.target.checked)
        }
    },
}
</script>
<style scoped>
    
    /*footer*/
    .todo-footer {
    height: 40px;
    line-height: 40px;
    padding-left: 6px;
    margin-top: 5px;
    }

    .todo-footer label {
    display: inline-block;
    margin-right: 20px;
    cursor: pointer;
    }

    .todo-footer label input {
    position: relative;
    top: -1px;
    vertical-align: middle;
    margin-right: 5px;
    }

    .todo-footer button {
    float: right;
    margin-top: 5px;
    }
</style>